/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.pay.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.biz.modular.pay.param.resp.BizPayOrderResp;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.biz.modular.pay.entity.BizPayOrder;
import vip.xiaonuo.biz.modular.pay.param.BizPayOrderAddParam;
import vip.xiaonuo.biz.modular.pay.param.BizPayOrderEditParam;
import vip.xiaonuo.biz.modular.pay.param.BizPayOrderIdParam;
import vip.xiaonuo.biz.modular.pay.param.BizPayOrderPageParam;
import vip.xiaonuo.biz.modular.pay.service.BizPayOrderService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 互助金订单信息控制器
 *
 * @author 薛守立
 * @date  2024/09/05 18:07
 */
@Tag(name = "互助金订单信息控制器")
@RestController
@Validated
public class BizPayOrderController {

    @Resource
    private BizPayOrderService bizPayOrderService;

    private static final Logger logger = LoggerFactory.getLogger(BizPayOrderController.class);

    /**
     * 获取互助金订单信息分页
     *
     * @author 薛守立
     * @date  2024/09/05 18:07
     */
    @Operation(summary = "获取互助金订单信息分页")
    @SaCheckPermission("/biz/payOrder/page")
    @GetMapping("/biz/payOrder/page")
    public CommonResult<Page<BizPayOrder>> page(BizPayOrderPageParam bizPayOrderPageParam) {
        return CommonResult.data(bizPayOrderService.page(bizPayOrderPageParam));
    }

    /**
     * 添加互助金订单信息
     *
     * @author 薛守立
     * @date  2024/09/05 18:07
     */
    @Operation(summary = "添加互助金订单信息")
    @CommonLog("添加互助金订单信息")
    @SaCheckPermission("/biz/payOrder/add")
    @PostMapping("/biz/payOrder/add")
    public CommonResult<String> add(@RequestBody @Valid BizPayOrderAddParam bizPayOrderAddParam) {
        bizPayOrderService.add();
        return CommonResult.ok();
    }

    /**
     * 编辑互助金订单信息
     *
     * @author 薛守立
     * @date  2024/09/05 18:07
     */
    @Operation(summary = "编辑互助金订单信息")
    @CommonLog("编辑互助金订单信息")
    @SaCheckPermission("/biz/payOrder/edit")
    @PostMapping("/biz/payOrder/edit")
    public CommonResult<String> edit(@RequestBody @Valid BizPayOrderEditParam bizPayOrderEditParam) {
        bizPayOrderService.edit(bizPayOrderEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除互助金订单信息
     *
     * @author 薛守立
     * @date  2024/09/05 18:07
     */
    @Operation(summary = "删除互助金订单信息")
    @CommonLog("删除互助金订单信息")
    @SaCheckPermission("/biz/payOrder/delete")
    @PostMapping("/biz/payOrder/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                       List<BizPayOrderIdParam> bizPayOrderIdParamList) {
        bizPayOrderService.delete(bizPayOrderIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取互助金订单信息详情
     *
     * @author 薛守立
     * @date  2024/09/05 18:07
     */
    @Operation(summary = "获取互助金订单信息详情")
    @SaCheckPermission("/biz/payOrder/detail")
    @GetMapping("/biz/payOrder/detail")
    public CommonResult<BizPayOrder> detail(@Valid BizPayOrderIdParam bizPayOrderIdParam) {
        return CommonResult.data(bizPayOrderService.detail(bizPayOrderIdParam));
    }

    /**
     * 退款操作
     *
     * @author 薛守立
     * @date  2024/09/18 18:07
     */
    @Operation(summary = "获取互助金订单信息详情")
    @SaCheckPermission("/biz/payOrder/orderBack")
    @GetMapping("/biz/payOrder/orderBack")
    public CommonResult<String> orderBack(@Valid BizPayOrderIdParam bizPayOrderIdParam) {
        return CommonResult.data("退款成功");
    }

    /**
     * 支付接口的回调(不做权限限制)
     *
     * @author 薛守立
     * @date  2024/09/18 18:07
     */
    @Operation(summary = "支付接口的回调")
    @PostMapping(value = "/biz/payOrder/callback",
        consumes = MediaType.APPLICATION_XML_VALUE,
        produces = MediaType.APPLICATION_XML_VALUE)
    @ResponseBody
    public CommonResult<String> callback(@RequestBody BizPayOrderResp bizPayOrderResp) {
        logger.info("甘肃银行支付回调接口：{}", bizPayOrderResp.toString());
        return CommonResult.data("success");
    }

    /**
     * 支付订单创建(不做权限限制)
     *
     * @author 薛守立
     * @date  2024/09/18 18:07
     */
    @Operation(summary = "支付接口的回调")
    @PostMapping(value = "/biz/payOrder/createOrder")
    @SaCheckPermission("/biz/payOrder/createOrder")
    public CommonResult<String> createOrder(@Valid BizPayOrderAddParam bizPayOrderAddParam) {
        logger.info("订单创建(类型选择)：{}", bizPayOrderAddParam.getOrderType());
      //  if(bizPayOrderAddParam.getOrderType().equals("wx")) bizPayOrderService.addWechatPay()
        return CommonResult.data("success");
    }




}


